#include "e2d/yml/physics/Serializer.h"
#include "e2d/core/physics/components.h"

using Serializer = e2d::BasicSerializer;

template<>
 void Serializer::Encode<e2d::PxMaterialData>(YAML::Node& node, const e2d::PxMaterialData& inst)
{
	SetVariable<float>(node, "m_StaticFriction", inst.m_StaticFriction);
	SetVariable<float>(node, "m_DynamicFriction", inst.m_DynamicFriction);
	SetVariable<float>(node, "m_Restitution", inst.m_Restitution);
}

template<>
 bool Serializer::Decode<e2d::PxMaterialData>(const YAML::Node& node, e2d::PxMaterialData& inst)
{
	GetVariable<float>(node, "m_StaticFriction", inst.m_StaticFriction);
	GetVariable<float>(node, "m_DynamicFriction", inst.m_DynamicFriction);
	GetVariable<float>(node, "m_Restitution", inst.m_Restitution);

	return true;
}

template<>
 void Serializer::Encode<e2d::PxBasicMap>(YAML::Node& node, const e2d::PxBasicMap& inst)
{
	SetVariable<e2d::PxMaterialData>(node, "m_MaterialData",inst.m_MaterialData);
	SetVariable<e2d::Transform>(node, "m_LocalPos", inst.m_LocalPos);
}

template<>
 bool Serializer::Decode<e2d::PxBasicMap>(const YAML::Node& node, e2d::PxBasicMap& inst)
{
	GetVariable<e2d::PxMaterialData>(node, "m_MaterialData", inst.m_MaterialData);
	GetVariable<glm::vec3>(node, "m_LocalPos", inst.m_LocalPos.m_Position);
	GetVariable<glm::vec3>(node, "m_Rotation", inst.m_LocalPos.m_Rotation);

	return true;
}


template<>
void Serializer::Encode<e2d::PxBoxShapeMap>(YAML::Node& node, const e2d::PxBoxShapeMap& inst)
{
	Encode<e2d::PxBasicMap>(node, inst);
	SetVariable<e2d::BoxShape>(node, "m_Box", inst.m_Box);;

}


template<>
bool Serializer::Decode<e2d::PxBoxShapeMap>(const YAML::Node& node, e2d::PxBoxShapeMap& inst)
{
	Decode<e2d::PxBasicMap>(node, inst);
	GetVariable<e2d::BoxShape>(node, "m_Box", inst.m_Box);

	return true;
}

template<>
void Serializer::Encode<e2d::PxShapeMap>(YAML::Node& node, const e2d::PxShapeMap& inst)
{
	SetArrayVariable<e2d::PxBoxShapeMap>(node, "m_BoxShapes", inst.m_BoxShapes);
}


template<>
bool Serializer::Decode<e2d::PxShapeMap>(const YAML::Node& node, e2d::PxShapeMap& inst)
{
	GetArrayVariable<e2d::PxBoxShapeMap>(node, "m_BoxShapes", inst.m_BoxShapes);
	return true;
}

